﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Xms.MQ
{
    public class CommonHelper
    {

        public static string SerializeObject(object obj)
        {
            return JsonConvert.SerializeObject(obj);
        }

        public static T DeserializeObject<T>(string obj)
        {
            return JsonConvert.DeserializeObject<T>(obj);
        }
        public static long GetTimeSpan(DateTime ndt)
        {
            TimeSpan ts1 = ndt - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts1.TotalMilliseconds);
        }
        public static DateTime GetTimebyTimeSpan(long timespan)
        {
            var tz = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return tz.AddMilliseconds(Convert.ToInt64(timespan));
        }
    }
}
